package com.wangwei.authoritySystem.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result implements Serializable {
    private int code;
    private String msg;
    private Object data;
    private Boolean exist;

    // success
    public  static Result success(Object data){
        Result rs = new Result();
        rs.setData(data);
        return success(200,"操作成功",data);
    }

    public  static Result success(int code,String msg,Object data){
        Result rs = new Result();
        rs.setCode(code);
        rs.setMsg(msg);
        rs.setData(data);
        return rs;
    }

    // fail
    public static Result fail(String msg){
        return fail(400,msg,null);
    }

    public  static Result fail(int code,String msg,Object data){
        Result rs = new Result();
        rs.setCode(code);
        rs.setMsg(msg);
        rs.setData(data);
        return rs;
    }

    //判断数据是否存在
    public static Result exist(String msg,Boolean isExist){
        Result rs = new Result();
        rs.setExist(isExist);
        rs.setCode(200);
        rs.setMsg(msg);
        return rs;
    }
}
